package com.lmk.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.lmk.domain.User;
import com.lmk.feign.UserService;
import com.lmk.sentinel.DowngradeUtil;
import com.lmk.sentinel.FuseDowngradeUtil;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
@RefreshScope // 动态刷新配置注解
public class OrderController {
    @Autowired
    private UserService userService;


    @GetMapping("/getUserById/{id}")
    @SentinelResource(
            value = "order-getUserById",
            blockHandler = "degradationMethod",
            blockHandlerClass = DowngradeUtil.class,
            fallback = "getUserByIdfallback",
            fallbackClass = FuseDowngradeUtil.class)// 开启限流或熔断
    public User getUserById(@PathVariable("id") Long id){
        return userService.getUserById(id);
    }


}
